package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.PolygonShape;

public class BoxFactory extends FixtureFactory<BoxFactory> 
{
	private float _hw, _hh, _a;
	private final Vector2 _c = new Vector2();
	private PolygonShape _shape;
	
	public BoxFactory()
	{
		this(false);
	}
	
	BoxFactory(boolean managed)
	{
		super(managed);
		_shape = new PolygonShape();
		_def.shape = _shape;
	}
	
	public BoxFactory size(float hw, float hh)
	{
		_hw = hw;
		_hh = hh;
		return this;
	}
	
	public BoxFactory at(float x, float y)
	{
		_c.set(x, y);
		return this;
	}
	
	public BoxFactory rotated(float a)
	{
		_a = a;
		return this;
	}
	
	@Override 
	public void clear()
	{
		super.clear();
		
		_hw = _hh = 0.5f;
		_a = 0;
		_c.set(0, 0);
	}
	
	@Override
	public Fixture create(Body b)
	{
		_shape.setAsBox(_hw, _hh, _c, _a);
		return super.create(b);
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
